"use strict";
/**
 * @author zhaojiuyi
 * @date 2022/7/5-17:02
 * @version 1.0.0
 */
const mutations = {
  setToken: function (state, data) {
    window.sessionStorage.setItem('token', data);
    state.token = data;
  },
  setUserName: function (state, data) {
    state.username = data
  },
  // 用户根目录
  setRootFolder: function (state, rootFolder) {
    state.rootFolder.folderId = rootFolder.folderId
    state.rootFolder.folderName = rootFolder.folderName
  },
  // 修改当前文件夹对象
  setFolder: function (state, folder) {
    state.folder.folderId = folder.folderId
    state.folder.folderName = folder.folderName
    let index = state.pathList.findIndex(item=>{
      return item.folderId === state.folder.folderId
    })
    if (index >= 0){
      state.pathList = state.pathList.slice(0,index)
    }
  },
  // 当前文件路径 ， 列表
  addFolderPath: function (state, folder) {
    state.pathList.push({
      folderId: folder.folderId,
      folderName: folder.folderName
    })
  },
  vuexInit: function (state) {
    state.token = window.sessionStorage.getItem('token');
    state.rootFolder =  {folderId: '', folderName: ''};//初始化
    state.folder =  {folderId: '', folderName: ''};//初始化
    state.pathList = [];
  },
  // folderPathInit: function (state){
  //   state.pathList = []
  // }
}
export {mutations}
